home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Compilers⁄Interps / little-c / Ex1.c next >
C/C++ Source or Header  |  1993-10-04  |  875b  |  50 lines

  1. /* C Interpreter Demonstration Program 
  2.    This program demonstrates all features
  3.    of C that are recognized by this C interpreter.
  4. */
  5. int i, j;   /* global vars */
  6. char ch;
  7.  
  8. main()
  9. {  
  10.   int i, j;  /* local vars */
  11.   puts("C Demo Program.");
  12.   print_alpha();
  13.   do {
  14.     puts("enter a number (0 to quit): ");
  15.     i = getnum();
  16.     if(i < 0 ) {
  17.       puts("numbers must be positive, try again");
  18.     }
  19.     else {
  20.       for(j = 0; j < i; j=j+1) {
  21.         print(j);
  22.         print("summed is");
  23.         print(sum(j));
  24.         puts("");
  25.       }
  26.     }
  27.   } while(i!=0);
  28. }
  29.  
  30. /* Sum the values between 0 and num. */
  31. sum(int num)
  32. {
  33.   int running_sum;
  34.   running_sum = 0;
  35.   while(num) {
  36.     running_sum = running_sum + num;
  37.     num = num - 1;
  38.   }
  39.   return running_sum;
  40. }
  41.  
  42. /* Print the alphabet. */
  43. print_alpha()
  44. {
  45.   for(ch = 'A'; ch<='Z'; ch = ch + 1) {
  46.     putch(ch);
  47.   }
  48.   puts("");
  49. }
  50.